package com.pzhu.controller;

import com.pzhu.service.LoginService;
import com.pzhu.service.impl.LoginServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginServlet extends HttpServlet {
    private LoginService loginService = new LoginServiceImpl();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//      设置编码
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
//      获得数据
        String uname = req.getParameter("uname");
        String pwd = req.getParameter("pwd");
//      调用service层处理数据
        boolean flag = loginService.checkUser(uname,pwd);
//      处理结果
        if (flag){
            resp.getWriter().write("登录成功");
        }else{
            resp.getWriter().write("登录失败");
        }

    }
}
